package com.stoken.dao;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.stoken.domain.AchievementList;
import com.stoken.domain.MemberRegisterInfo;
import com.symbio.commons.Page;
import com.symbio.dao.hibernate.GenericDaoImpl;
import com.symbio.utils.HibernateUtils;

@Repository("achievementListDao")
public class AchievementListDao extends GenericDaoImpl<AchievementList, Long> {
    
	/**
	 * 根据日期和用户名查询业绩详细信息
	 * @param date
	 * @param account
	 * @return
	 */
	public AchievementList getAchievemntListByAccountAndDate(Date date,String account){		
		 return this.find("from AchievementList where baseUsername.baseUsername = ? and bringTime = ?", new Object[]{account,date});
	}	
	
	/**
	 * 初始化数据
	 * @param memberRegisterInfo
	 */
	public void initMemberAchievementInfo(MemberRegisterInfo memberRegisterInfo){
	     AchievementList achievementList = new AchievementList(memberRegisterInfo);	     
		 this.save(achievementList);
	}
	
	public Page<AchievementList> find(Page<AchievementList> pageData,String baseUserName) {		
	    Criteria criteria = HibernateUtils.createCriteria(getSession(), entityClass);		
		criteria.createAlias("baseUsername", "memberUserInfo",Criteria.INNER_JOIN, Restrictions.eq("memberUserInfo.baseUsername", baseUserName));		
		HibernateUtils.setParameter(criteria, pageData);		
		pageData.setResult(criteria.list());		
		return pageData;		
	}
	
	
}
